VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "GridClass"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Private Grid(100, 100) As Integer

Private Function WithinBounds(ByVal X As Integer, ByVal Y As Integer) As Boolean
If X >= 0 And Y >= 0 And X <= 100 And Y <= 100 Then
WithinBounds = True
Exit Function
End If
WithinBounds = False
End Function

Public Property Get GetTile(ByVal X As Integer, ByVal Y As Integer) As Integer
If WithinBounds(X, Y) Then
GetTile = Grid(X, Y): Exit Property
End If
GetTile = -1
End Property

Public Property Let SetTile(ByVal X As Integer, ByVal Y As Integer, ByVal Value As Integer)
If WithinBounds(X, Y) Then
Grid(X, Y) = Value
End If
End Property

Private Sub Class_Initialize()
Randomize
Dim Y As Integer
Dim X As Integer
Dim n As Integer
Dim smooth As Integer
Dim TempGrid(100, 100) As Byte

For Y = 0 To 100
For X = 0 To 100
Grid(X, Y) = 0
Next
Next

For I = 1 To 50
Grid(Rnd * 100, Rnd * 100) = 1
Next

For I = 1 To 5
'copy base grid to temp grid
For Y = 0 To 100
For X = 0 To 100
TempGrid(X, Y) = Grid(X, Y)
Next
Next

'wilted growth
For Y = 0 To 100
For X = 0 To 100
n = 0
If Grid(X, Y) = 0 Then
If X - 1 > 0 And Y - 1 > 0 Then If Grid(X - 1, Y - 1) = 1 Then n = n + 1
If Y - 1 > 0 Then If Grid(X, Y - 1) = 1 Then n = n + 1
If X + 1 < 100 And Y - 1 > 0 Then If Grid(X + 1, Y - 1) = 1 Then n = n + 1
If X - 1 > 0 Then If Grid(X - 1, Y) = 1 Then n = n + 1
If X + 1 < 100 Then If Grid(X + 1, Y) = 1 Then n = n + 1
If X - 1 > 0 And Y + 1 < 100 Then If Grid(X - 1, Y + 1) = 1 Then n = n + 1
If Y + 1 < 100 Then If Grid(X, Y + 1) = 1 Then n = n + 1
If X + 1 < 100 And Y + 1 < 100 Then If Grid(X + 1, Y + 1) = 1 Then n = n + 1
If n >= 1 And (Rnd * 100 <= 70) Then TempGrid(X, Y) = 1
End If

Next
Next

'copy complete modifications over to base grid
For Y = 0 To 100
For X = 0 To 100
Grid(X, Y) = TempGrid(X, Y)
Next
Next

Next


For I = 1 To 5

'copy base grid to temp grid
For Y = 0 To 100
For X = 0 To 100
TempGrid(X, Y) = Grid(X, Y)
Next
Next


For Y = 0 To 100
For X = 0 To 100

If Grid(X, Y) = 0 Then
n = 0
If X - 1 > 0 And Y - 1 > 0 Then If Grid(X - 1, Y - 1) = 1 Then n = n + 1
If Y - 1 > 0 Then If Grid(X, Y - 1) = 1 Then n = n + 1
If X + 1 < 100 And Y - 1 > 0 Then If Grid(X + 1, Y - 1) = 1 Then n = n + 1
If X - 1 > 0 Then If Grid(X - 1, Y) = 1 Then n = n + 1
If X + 1 < 100 Then If Grid(X + 1, Y) = 1 Then n = n + 1
If X - 1 > 0 And Y + 1 < 100 Then If Grid(X - 1, Y + 1) = 1 Then n = n + 1
If Y + 1 < 100 Then If Grid(X, Y + 1) = 1 Then n = n + 1
If X + 1 < 100 And Y + 1 < 100 Then If Grid(X + 1, Y + 1) = 1 Then n = n + 1
If n >= 4 Then TempGrid(X, Y) = 1
End If

If Grid(X, Y) = 1 Then
n = 0
If X - 1 > 0 And Y - 1 > 0 Then If Grid(X - 1, Y - 1) = 1 Then n = n + 1
If Y - 1 > 0 Then If Grid(X, Y - 1) = 1 Then n = n + 1
If X + 1 < 10 And Y - 1 > 0 Then If Grid(X + 1, Y - 1) = 1 Then n = n + 1
If X - 1 > 0 Then If Grid(X - 1, Y) = 1 Then n = n + 1
If X + 1 < 10 Then If Grid(X + 1, Y) = 1 Then n = n + 1
If X - 1 > 0 And Y + 1 < 100 Then If Grid(X - 1, Y + 1) = 1 Then n = n + 1
If Y + 1 < 100 Then If Grid(X, Y + 1) = 1 Then n = n + 1
If X + 1 < 100 And Y + 1 < 100 Then If Grid(X + 1, Y + 1) = 1 Then n = n + 1
If n >= 5 Then TempGrid(X, Y) = 2
End If


Next
Next

'copy complete modifications over to base grid
For Y = 0 To 100
For X = 0 To 100
Grid(X, Y) = TempGrid(X, Y)
Next
Next

Next




'copy base grid to temp grid
For Y = 0 To 100
For X = 0 To 100
TempGrid(X, Y) = Grid(X, Y)
Next
Next

For Y = 0 To 100
For X = 0 To 100
smooth = 0
If X - 1 > 0 And Y - 1 > 0 Then smooth = smooth + Grid(X - 1, Y - 1)
If Y - 1 > 0 Then smooth = smooth + Grid(X, Y - 1)
If X + 1 < 100 And Y - 1 > 0 Then smooth = smooth + Grid(X + 1, Y - 1)
If X - 1 > 0 Then smooth = smooth + Grid(X - 1, Y)
If X + 1 < 100 Then smooth = smooth + Grid(X + 1, Y)
If X - 1 > 0 And Y + 1 < 100 Then smooth = smooth + Grid(X - 1, Y + 1)
If Y + 1 < 100 Then smooth = smooth + Grid(X, Y + 1)
If X + 1 < 100 And Y + 1 < 100 Then smooth = smooth + Grid(X + 1, Y + 1)
smooth = (smooth / 8)

TempGrid(X, Y) = smooth
Next
Next


'copy complete modifications over to base grid
For Y = 0 To 100
For X = 0 To 100
Grid(X, Y) = TempGrid(X, Y)
Next
Next

'Dir = 255
'MainFrm.Show
'Call GameLoop
'Exit Sub

For I = 1 To 50
Grid(Rnd * 100, Rnd * 100) = 3
Next

For I = 1 To 5

'copy base grid to temp grid
For Y = 0 To 100
For X = 0 To 100
TempGrid(X, Y) = Grid(X, Y)
Next
Next


For Y = 0 To 100
For X = 0 To 100

If Grid(X, Y) < 2 Then
n = 0
If X - 1 > 0 And Y - 1 > 0 Then If Grid(X - 1, Y - 1) = 3 Then n = n + 1
If Y - 1 > 0 Then If Grid(X, Y - 1) = 3 Then n = n + 1
If X + 1 < 100 And Y - 1 > 0 Then If Grid(X + 1, Y - 1) = 1 Then n = n + 1
If X - 1 > 0 Then If Grid(X - 1, Y) = 3 Then n = n + 1
If X + 1 < 100 Then If Grid(X + 1, Y) = 3 Then n = n + 1
If X - 1 > 0 And Y + 1 < 100 Then If Grid(X - 1, Y + 1) = 3 Then n = n + 1
If Y + 1 < 100 Then If Grid(X, Y + 1) = 3 Then n = n + 1
If X + 1 < 100 And Y + 1 < 100 Then If Grid(X + 1, Y + 1) = 3 Then n = n + 1
If n >= 6 Or (n >= 1 And Rnd * 100 < 40) Then TempGrid(X, Y) = 3
End If


Next
Next

'copy complete modifications over to base grid
For Y = 0 To 100
For X = 0 To 100
Grid(X, Y) = TempGrid(X, Y)
Next
Next

Next

End Sub
